package com.lagou.subjectone;

import java.io.Serializable;

/**
 * 学生类  支持，可序列化
 */
public class Student implements Serializable {
    private static final long serialVersionUID = 4802940292861587186L;
    private int num;
    private String name;
    private int age;

    /**
     * 构造函数
     *
     * @param num
     * @param name
     * @param age
     */
    public Student(int num, String name, int age) {
        setNum(num);
        setName(name);
        setAge(age);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;
        //学号不同  就不同
        if (num != student.num)
            return false;
        else
            return true;
    }

    @Override
    public String toString() {
        return
                "学号：" + num +
                        ", 姓名：" + name +
                        ", 年龄：" + age;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        //设置学号最大9999 测试用
        if (num > 0 && num < 9999) {
            this.num = num;
        } else {
            try {
                throw new NumException("学号不合理哦！！！");
            } catch (NumException e) {
                e.printStackTrace();
            }
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age > 0 && age < 150) {
            this.age = age;
        } else {
            try {
                throw new AgeException("年龄不合理哦！！！");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }
    }
}
